import type { ConsultType } from '@/enums'
import type { ConsultIllnessForm, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义响应式数据来保存问诊的数据
    const consult = ref<PartialConsult>({})
    // 收集就诊的类型
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 收集 极速问诊类型 0普通1三甲
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 收集 科室id
    const setDepId = (id: string) => {
      consult.value.depId = id
    }
    // 收集 病情描述
    const setIllness = (illness: ConsultIllnessForm) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    // 记录患者id
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }
    // 记录优惠券
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }
    // 清理所有的问诊数据
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId,
      clear
    }
  },
  {
    persist: true
  }
)
